bitkeeper revision 1.765 (4048b92eZ-VqpZdWj-oHI1tRK9Ft1A)
authormwilli2@equilibrium.research.intel-research.net <mwilli2@equilibrium.research.intel-research.net>
Fri, 5 Mar 2004 17:30:22 +0000 (17:30 +0000)
committermwilli2@equilibrium.research.intel-research.net <mwilli2@equilibrium.research.intel-research.net>
Fri, 5 Mar 2004 17:30:22 +0000 (17:30 +0000)
Update to trace code for new memory protection model.

tools/xentrace/xentrace.c
xen/common/trace.c

index 4fa6c696e1d02fc7f0fc738b6ab87c1c578b75bd..73846f39d1e24ae1a201642bac2a20c88fcc872a 100644 (file)
@@ -131,19 +131,16 @@ struct t_buf *map_tbufs(unsigned long tbufs_phys, unsigned int num,
 {
     int dm_fd;                               /* file descriptor for /dev/mem */
     struct t_buf *tbufs_mapped;
-    unsigned int page_size = getpagesize();
-    unsigned int off_in_pg = (tbufs_phys % page_size);
-
-    tbufs_phys -= off_in_pg; /* correct tbufs_phys if not page-aligned */
 
     dm_fd = open("/dev/mem", O_RDONLY);
+
     if ( dm_fd < 0 ) 
     {
         PERROR("Open /dev/mem when mapping trace buffers\n");
         exit(EXIT_FAILURE);
     }
 
-    tbufs_mapped = (struct t_buf *)mmap(NULL, size * num + off_in_pg,
+    tbufs_mapped = (struct t_buf *)mmap(NULL, size * num,
                                         PROT_READ, MAP_SHARED,
                                         dm_fd, (off_t)tbufs_phys);
 
@@ -155,8 +152,7 @@ struct t_buf *map_tbufs(unsigned long tbufs_phys, unsigned int num,
         exit(EXIT_FAILURE);
     }
 
-    /* add offset to get buffers in case original address wasn't pg aligned */
-    return (struct t_buf *)((unsigned long)tbufs_mapped + off_in_pg);
+    return (struct t_buf *)tbufs_mapped;
 }
 
 
index aa2e7b949fd91671a265346bb1b7c3c402d40e17..76c39a67bd50650dd85d7455d0105c06b904a03f 100644 (file)
@@ -49,8 +49,8 @@ int tb_init_done = 0;
 void init_trace_bufs(void)
 {
     extern int opt_tbuf_size;
-
-    int           i;
+    int           i, pages_order;
+    unsigned long total_size;
     char         *rawbuf;
     struct t_buf *buf;
     
@@ -60,12 +60,27 @@ void init_trace_bufs(void)
         return;
     }
 
-    if ( (rawbuf = kmalloc(smp_num_cpus * opt_tbuf_size * PAGE_SIZE,
-                           GFP_KERNEL)) == NULL )
+    /* calculate page_order - we'll allocate 2^page_order pages */
+    pages_order = 0;
+    total_size = smp_num_cpus * opt_tbuf_size;
+    
+    while( (total_size) >> ( pages_order + 1 ) )
+        pages_order++;
+
+    /* if total_size is not an exact power of two then over-allocate */
+    if( total_size & ~( 1 << pages_order ) )
+        pages_order++;
+
+    /* we allocate 2^page_order pages to hold the data */
+    if ( (rawbuf = (char *)__get_free_pages(GFP_KERNEL, pages_order)) == NULL )
     {
         printk("Xen trace buffers: memory allocation failed\n");
         return;
     }
+
+    /* share pages so that xentrace can map them */
+    for( i = 0; i < total_size; i++)
+        SHARE_PFN_WITH_DOMAIN( &frame_table[(__pa(rawbuf)>>PAGE_SHIFT)+i], 0);
     
     for ( i = 0; i < smp_num_cpus; i++ )
     {